package io.hepu.robotize.service.impl;

import io.hepu.robotize.base.BaseService;
import io.hepu.robotize.dao.RoleMapper;
import io.hepu.robotize.enums.RoleType;
import io.hepu.robotize.model.Role;
import io.hepu.robotize.service.IRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleService extends BaseService<Role, String, RoleMapper> implements IRoleService {

    @Override
    public int findPrivsByUserId(String userId) {
        String[] roleNames = findByUserId(userId).stream().map(Role::getCode).toArray(String[]::new);
        return RoleType.privs(roleNames);
    }

    @Override
    public List<Role> findByUserId(String userId) {
        return getResposity().selectByUserId(userId);
    }
}
